package com.akw.web.controller;

import com.akw.web.bean.Person;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping("/person")
    public Person person() {
        Person person = new Person();
        person.setId(1L);
        person.setAge(18);
        person.setUserName("AKW");
        person.setEmail("2497744746@qq.com");
        return person;
    }

    @GetMapping("/list")
    public List<Person> list() {
        List<Person> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Person p = new Person();
            p.setId(1L);
            p.setAge(18);
            p.setUserName("AKW");
            p.setEmail("2497744746@qq.com");
            list.add(p);
        }
        int i = 1 / 0;
        return list;
    }

    public static void main(String[] args) throws JsonProcessingException {
        Person person = new Person();
        person.setId(1L);
        person.setAge(18);
        person.setUserName("AKW");
        person.setEmail("2497744746@qq.com");
        YAMLFactory yamlFactory = new YAMLFactory();
        yamlFactory.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER);
        ObjectMapper mapper = new ObjectMapper(yamlFactory);
        String s = mapper.writeValueAsString(person);
        System.out.println(s);

    }
}
